<?php
/**
 * @特惠赚、获取淘宝商品接口数据逻辑
 * Author: 小谢
 * Date: 2019-5-14
 */
namespace app\admin\logic;
use taobao\TopClient;
use taobao\request\TbkItemInfosGetRequest;

class TaobaoLogic
{
    
    /**
     * @brief 获取淘宝接口数据
     * @param Int $num_iid 淘宝商品id
     * return Array
     */
    public function getTaobaoGoods($num_iid) {
            $api_config = M("api_config")->where(["code" => "taobao"])->getField("config");
            $config = unserialize($api_config);
            $c = new TopClient($config["app_key"],$config["app_secret"]);
            $req = new TbkItemInfosGetRequest();
            $req->setPlatform("1");
            $req->setNumIids($num_iid);
            $resp = $c->execute($req);
            $arr_info = objtoarr($resp);
            if(isset($arr_info['results'])) {
                return $arr_info['results']['n_tbk_item'][0];
            }
            return $arr_info;
    }
    
}